<template>
    <div class="app-container">
  
      <div class="search-div">
        <el-form label-width="70px" size="small">
          <el-row>
            <el-col :span="4">
              <el-input style="width: 95%" v-model="searchObj.name" placeholder="卷子名称"></el-input>
            </el-col>
            <el-col :span="8">
              <el-form-item label="创建时间">
                <el-date-picker
                  v-model="createTimes"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始时间"
                  end-placeholder="结束时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="margin-right: 10px;width: 100%;"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row style="display:flex">
            <el-button type="primary" icon="el-icon-search" size="mini"  @click="fetchData()">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button>
          </el-row>
        </el-form>
      </div>
  
  
      <!-- 列表 -->
      <el-table
        v-loading="listLoading"
        :data="list"
        stripe
        border
        style="width: 100%;margin-top: 10px;">
        <el-table-column
          label="序号"
          width="50"
          align="center">
          <template slot-scope="scope">
            {{ (page - 1) * limit + scope.$index + 1 }}
          </template>
        </el-table-column>
  
        <el-table-column prop="name" label="卷子名称"/>
        <el-table-column prop="radioCount" label="单选个数" width="78"/>
        <el-table-column prop="multiCount" label="多选个数" width="78"/>
        <el-table-column prop="judgeCount" label="判断个数" width="78"/>
        <el-table-column prop="saqCount" label="论述个数" width="78"/>
        <el-table-column prop="radioScore" label="单选分数" width="78"/>
        <el-table-column prop="multiScore" label="多选分数" width="78"/>
        <el-table-column prop="judgeScore" label="判断分数" width="78"/>
        <el-table-column prop="saqScore" label="论述分数" width="78"/>
        <el-table-column prop="sumScore" label="总分" width="60"/>
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column label="操作"  align="center" fixed="right" width="150">
          <template slot-scope="scope">
            <el-button type="info" plain round icon="el-icon-edit-outline" size="mini" @click="Write(scope.row)" title="开始测验"/>
            <el-button type="primary" plain round v-if="$hasBP('bnt.Allwork.view')" icon="el-icon-more-outline" size="mini" @click="DetailView(scope.row)" title="查看详情"/>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-pagination
        :current-page="page"
        :total="total"
        :page-size="limit"
        style="padding: 30px 0; text-align: center;"
        layout="total, prev, pager, next, jumper"
        @current-change="fetchData"
      />
    </div>
  </template>
  <style>
      .search-div {
          padding:10px;border: 1px solid #EBEEF5;border-radius:3px;
      }
      .tools-div {
          margin-top: 10px;padding:10px;border: 1px solid #EBEEF5;border-radius:3px;
      }
  </style>
  <script>
  import api from '@/api/El/paper'
  const defaultForm = {
    id: '',
    name: '',
    radioScore:'',
    multiScore:'',
    judgeScore:'',
    saqScore:'',
    createTime:'',
    updateTime:'',
  }
  export default {
    data() {
      return {
        reFreshIcon:'el-icon-refresh-right', //刷新图标展示
        reFreshDisabled : false,    //刷新是否可以点击
        listLoading: true, // 数据是否正在加载
        list: null, // banner列表
        total: 0, // 数据库中的总记录数
        page: 1, // 默认页码
        limit: 10, // 每页记录数
        searchObj: {    //条件查询
          name:''
        },
  
        createTimes: [],
  
        checkAll: false, // 是否全选
  
        dialogVisible: false,
        Elpaper: defaultForm,

      }
    },
    // 生命周期函数：内存准备完毕，页面渲染成功
    mounted() {
      this.fetchData()
    },
  
    methods: {
      
      // 加载banner列表数据
      fetchData(page = 1) {
        this.page = page
        if(this.createTimes && this.createTimes.length ==2) {
          this.searchObj.createTimeBegin = this.createTimes[0]
          this.searchObj.createTimeEnd = this.createTimes[1]
        }
  
        api.getPageList(this.page, this.limit, this.searchObj).then(
          response => {
            this.list = response.data.records
            this.total = response.data.total

            this.list.forEach(element => {
                element.sumScore = element.radioCount * element.radioScore + element.multiCount * element.multiScore + element.judgeCount * element.judgeScore + element.saqCount * element.saqScore
            });
            // 数据加载并绑定成功
            this.listLoading = false
          }
        )
  
      },
  
      // 重置查询表单
      resetData() {
        this.searchObj = {}
        this.createTimes = []
        this.fetchData()
      },

        //去验证页
        Write(row){
          this.$router.push('/work/Verify?id='+row.id+'&name='+row.name);
        },
        //去详情页
        DetailView(row){          
          this.$router.push('/work/PaperView?id='+row.id+'&name='+row.name);
        }
    }
  }
  </script>